package com.zr.daoimpl;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.zr.dao.DeliverypointDaoLPN;
import com.zr.model.Deliverypoint;
import com.zr.vo.Dp_DsVO;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Repository("dpDao")
public class DeliverypointDaoImplLPN  extends BaseDaOImpl implements DeliverypointDaoLPN{

	@Override
	public JSONArray findDP() {
		JSONArray j = new JSONArray();
		String hql = " from Deliverypoint dp";
		Query query = this.getCurrentSession().createQuery(hql);
		List<Deliverypoint>  obj = query.list();	
		Iterator<Deliverypoint> it = obj.iterator();
		while(it.hasNext()) {
			JSONObject js=new JSONObject();
			Deliverypoint dp=it.next();
			js.put("dpId",dp.getDpId());
			js.put("dpName", dp.getDpName());
			js.put("dpGrade", dp.getDpGrade());
			j.add(js);					  
		}		
		return j;
	}

	@Override
	public JSONArray findDpByUid(int uid) {
		JSONArray j = new JSONArray();
		String sql = "select  dp.dpId,dp.dpName,dp.dpGrade "
				+ "from deliverypoint as dp,employeeinformation as ei "
				+ "where ei.dpId=dp.dpId and  ei.uid = :uid";
		
		Query query = this.getCurrentSession().createSQLQuery(sql);
		query.setInteger("uid", uid);
		List<Deliverypoint> ss = query.setResultTransformer(Transformers.aliasToBean(Deliverypoint.class)).list();
		for (Deliverypoint deliverypoint : ss) {
			JSONObject jo = new JSONObject();
			jo.put("dpId", deliverypoint.getDpId());
			jo.put("dpName", deliverypoint.getDpName());
			jo.put("dpGrade", deliverypoint.getDpGrade());
			j.add(jo);
		}
		return j;
	}

}
